home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / emacs-19.000 / emacs-19 / usr / local / info / viper-2 < prev    next >
Encoding:
GNU Info File  |  1995-09-11  |  35.4 KB  |  835 lines

  1. This is Info file ../info/viper, produced by Makeinfo-1.55 from the
  2. input file viper.texi.
  3.  
  4.    %
  5.  
  6. Distribution
  7. ************
  8.  
  9. Copyright (C) 1991 Aamod Sane
  10. Copyright (C) 1994 Michael Kifer
  11.  
  12.    Permission is granted to make and distribute verbatim copies of this
  13. manual provided the copyright notice and this permission notice are
  14. preserved on all copies.
  15.  
  16.    Permission is granted to copy and distribute modified versions of
  17. this manual under the conditions for verbatim copying, provided that
  18. the entire resulting derived work is distributed under the terms of a
  19. permission notice identical to this one.
  20.  
  21.    Permission is granted to copy and distribute translations of this
  22. manual into another language, under the same conditions as for modified
  23. versions.
  24.  
  25. 
  26. File: viper,  Node: New Commands,  Next: Useful Packages,  Prev: Movement and Markers,  Up: Improvements over Vi
  27.  
  28. New Commands
  29. ============
  30.  
  31.    These commands have no Vi analogs.
  32.  
  33. `C-x, C-c'
  34.      `C-x' will exit from Vi state and return to Emacs state
  35.      *temporarily*. If you hit one of these keys, Emacs will believe
  36.      that you hit that key in Emacs state. For example, if you hit `C-x'
  37.      followed by `2', then the current window will be split into 2 and
  38.      you will be in Vi state again. Except for novice users, `C-c' is
  39.      also set to temporarily escape to Emacs and execute a command from
  40.      the current major mode.  `ESC' will do the same, if you configure
  41.      ESC as Meta by setting `vip-no-multiple-ESC' to nil in `.vip'.
  42.      *Note Customization::. `C-z' in Insert state will make Emacs think
  43.      `Meta' has been hit.
  44.  
  45. `\'
  46.      Escape to Emacs to execute a single Emacs command. For instance, `\
  47.      ESC' will act like a Meta key.
  48.  
  49. `Q'
  50.      `Q' is for query replace.  By default, each string to be replaced
  51.      is treated as regular expressions. You can use `(setq
  52.      vip-re-query-replace nil)' in your `.emacs' file to turn this off.
  53.      (For normal searches, `:se nomagic' will work. Note that `:se
  54.      nomagic' turns Regexps off completely, unlike Vi).
  55.  
  56. `v'
  57. `V'
  58. `C-v'
  59.      These keys are used to visit files.  `v' will switch to a buffer
  60.      visiting file whose name can be entered in the Minibuffer. `V' is
  61.      similar, but will use a window different from the current window.
  62.      `C-v' is like `V', except that a new frame (X window) will be used
  63.      instead of a new Emacs window.
  64.  
  65. `#'
  66.      If followed by a certain character CH, it becomes an operator whose
  67.      argument is the region determined by the motion command that
  68.      follows (indicated as <move>).  Currently, CH can be one of `c',
  69.      `C', `g', `q', and `s'. For instance, `#qr' will prompt you for a
  70.      string and then prepend this string to each line in the buffer.
  71.  
  72. `# c'
  73.      Change upper case characters in the region to lower case
  74.      (`downcase-region').  Emacs command `M-l' does the same for words.
  75.  
  76. `# C'
  77.      Change lower case characters in the region to upper case. For
  78.      instance, `# C 3 w' will capitalize 3 words from the current point
  79.      (`upcase-region').  Emacs command `M-l' does the same for words.
  80.  
  81. `# g'
  82.      Execute last keyboard macro for each line in the region
  83.      (`vip-global-execute').
  84.  
  85. `# q'
  86.      Insert specified string at the beginning of each line in the region
  87.      (`vip-quote-region').
  88.  
  89. `# s'
  90.      Check spelling of words in the region (`spell-region').  The
  91.      function used for spelling is determined from the variable
  92.      `vip-spell-function'.
  93.  
  94. `*'
  95.      Call last keyboard macro.
  96.  
  97. `m .'
  98.      Set mark at point and push old mark off the ring
  99.  
  100. `m<'
  101. `m>'
  102.      Set mark at beginning and end of buffer, respectively.
  103.  
  104. `m,'
  105.      Jump to mark and pop mark off the ring. *Note Mark: (emacs)Mark,
  106.      for more info.
  107.  
  108. `] register'
  109.      View contents of register
  110.  
  111. `[ textmarker'
  112.      View filename and position of textmarker
  113.  
  114. `@#'
  115. `@register'
  116. `@!'
  117.      Begin/end keyboard macro. @register has a different meaning when
  118.      used after a `@#'. *Note Macros and Registers::, for details
  119.  
  120. `[]'
  121.      Go to end of heading.
  122.  
  123. `g <*movement command*>'
  124.      Search buffer for text delimited by movement command. The canonical
  125.      example is `gw' to search for word under the cursor.  *Note
  126.      Improved Search::, for details.
  127.  
  128. `_'
  129.      Meta key when in Vi state.*Note Vi State::, for an explanation.
  130.  
  131. `C-g and C-]'
  132.      Quit and Abort Recursive edit. These may be necessary on occasion.
  133.      *Note Vi State::, for a reason.
  134.  
  135. `C-c g'
  136.      Hitting `C-c' followed by `g' will display the information on the
  137.      current buffer. This is the same as hitting  `C-g' in Vi, but, as
  138.      explained above, `C-g' is needed for other purposes in Emacs.
  139.  
  140. `C-c /'
  141.      Without a prefix argument, this command toggles
  142.      case-sensitive/case-insensitive search modes and plain
  143.      vanilla/regular expression search. With the prefix argument 1,
  144.      i.e., `1 C-c /', this toggles case-sensitivity; with the prefix
  145.      argument 2, toggles plain vanilla search and search using regular
  146.      expressions. *Note Viper Specials::, for alternative ways to invoke
  147.      this function.
  148.  
  149. `M-p and M-n'
  150.      In the Minibuffer, these commands navigate through the minibuffer
  151.      histories, such as the history of search strings, Ex commands, etc.
  152.  
  153. `C-c M-p and C-c M-n'
  154.      In Insert or Replace state, these commands let  the user peruse
  155.      the history of insertion strings used in previous insert or replace
  156.      commands. Try to hit `C-c M-p' or `C-c M-n' repeatedly and see what
  157.      happens. *Note Viper Specials::, for more.
  158.  
  159.      In Vi state, these commands let the user peruse the history of
  160.      Vi-style destructive commands, such as `dw', `J', `a', etc.  By
  161.      repeatedly typing `C-c M-p' or `C-c M-n' you will cycle Viper
  162.      through the recent history of Vi commands, displaying the commands
  163.      one by one. Once an appropriate command is found, it can be
  164.      executed by typing ``.''.
  165.  
  166.      Since typing `C-c M-p' is tedious, it is more convenient to bind an
  167.      appropriate function to a function key on the keyboard and use
  168.      that key.  *Note Viper Specials::, for details.
  169.  
  170. `Ex commands'
  171.      The commands `:args', `:next', `:pre' behave differently. `:pwd'
  172.      exists to get current directory.  The commands `:b' and `:B'
  173.      switch buffers around. *Note File and Buffer Handling::, for
  174.      details.  There are also the new commands `:RelatedFile' and
  175.      `PreviousRelatedFile' (which abbreviate to `R' and `P',
  176.      respectively. *Note Viper Specials::, for details.
  177.  
  178.    Apart from the new commands, many old commands have been enhanced.
  179. Most notably, Vi style macros are much more powerful in Viper than in
  180. Vi. *Note Vi Macros::, for details.
  181.  
  182. 
  183. File: viper,  Node: Useful Packages,  Prev: New Commands,  Up: Improvements over Vi
  184.  
  185. Useful Packages
  186. ===============
  187.  
  188.    Some Emacs packages are mentioned here as an aid to the new Viper
  189. user, to indicate what Viper is capable of.  A vast number comes with
  190. the standard Emacs distribution, and many more exist on the net and on
  191. the archives.
  192.  
  193.    This manual also mentions some Emacs features a new user should know
  194. about. The details of these are found in the GNU Emacs Manual.
  195.  
  196.    The features first. For details, look up the Emacs Manual.
  197.  
  198. `Make'
  199.      Makes and Compiles can be done from the editor. Error messages
  200.      will be parsed and you can move to the error lines.
  201.  
  202. `Shell'
  203.      You can talk to Shells from inside the editor. Your entire shell
  204.      session can be treated as a file.
  205.  
  206. `Mail'
  207.      Mail can be read from and sent within the editor. Several
  208.      sophisticated packages exist.
  209.  
  210. `Language Sensitive Editing'
  211.      Editing modes are written for most computer  languages in
  212.      existence. By controlling indentation, they catch punctuation
  213.      errors.
  214.  
  215.    The packages, below, represents a drop in the sea of special-purpose
  216. packages that come with standard distribution of Emacs 19.
  217.  
  218. `Transparent FTP'
  219.      `ange-ftp.el' can ftp from the editor to files on other machines
  220.      transparent to the user.
  221.  
  222. `RCS Interfaces'
  223.      `vc.el' for doing RCS commands from inside the editor
  224.  
  225. `Directory Editor'
  226.      `dired.el' for editing contents of directories and for navigating
  227.      in the file system.
  228.  
  229. `Syntactic Highlighting'
  230.      `hilit19.el' and `font-lock.el' for automatic highlighting various
  231.      parts of a buffer using different fonts and colors.
  232.  
  233. `Saving Emacs Configuration'
  234.      `desktop.el' for saving/restoring configuration on Emacs
  235.      exit/startup.
  236.  
  237. `Spell Checker'
  238.      `ispell.el' for spell checking the buffer, words, regions, etc.
  239.  
  240. `File and Buffer Comparison'
  241.      `ediff.el' for finding differences between files and for applying
  242.      patches.
  243.  
  244. Emacs Lisp archives exist on `archive.cis.ohio-state.edu' and
  245. `wuarchive.wustl.edu'
  246.  
  247. 
  248. File: viper,  Node: Customization,  Next: Commands,  Prev: Improvements over Vi,  Up: Top
  249.  
  250. Customization
  251. *************
  252.  
  253.    Customization can be done in 2 ways.
  254.  
  255.    * Elisp code in a `.vip' file in your home directory. Viper loads
  256.      `.vip' just before it does the binding for mode hooks. This is the
  257.      recommended method.
  258.  
  259.    * Elisp code in your `.emacs' file before and after the `(require
  260.      'viper)' line. This method is not recommended, unless you are know
  261.      what you are doing.
  262.  
  263. Emacs customization is done in Emacs Lisp. For the common cases,
  264. examples are provided that you can use directly.
  265.  
  266. * Menu:
  267.  
  268. * Rudimentary Changes::         Simple constant definitions.
  269. * Keybindings::             Enabling Emacs Keys, Rebinding keys, etc.
  270. * Packages that Change Keymaps:: How to deal with such beasts.
  271. * Viper Specials::         Special Viper commands.
  272. * Vi Macros::                How to do Vi style macros.
  273.  
  274. 
  275. File: viper,  Node: Rudimentary Changes,  Next: Keybindings,  Prev: Customization,  Up: Customization
  276.  
  277. Rudimentary Changes
  278. ===================
  279.  
  280.    An easy way to customize Viper is to change the values of constants
  281. used in Viper.  Here is the list of the constants used in Viper and
  282. their default values. The corresponding :se command is also indicated.
  283. (The symbols `t' and `nil' represent "true" and "false" in Lisp).
  284.  
  285.    Viper supports both the abbreviated Vi variable names and their full
  286. names. Variable completion is done on full names only. `TAB' and `SPC'
  287. complete variable names. Typing `=' will complete the name and then
  288. will prompt for a value, if applicable. For instance, `:se auSPC' will
  289. complete the command to `:set autoindent'; `:se taSPC' will complete
  290. the command and prompt further like this: `:set tabstop = '.  However,
  291. typing `:se tsSPC' will produce a "No match" message because `ts' is an
  292. abbreviation for `tabstop' and Viper supports completion on full names
  293. only. However, you can still hit `RET' or `=', which will complete the
  294. command like this: `:set ts = ' and Viper will be waiting for you to
  295. type a value for the tabstop variable.  To get the full list of Vi
  296. variables, type `:se SPC TAB'.
  297.  
  298. `vip-auto-indent nil'
  299. `:se ai (:se autoindent)'
  300.      If `t' then enable auto indentation.  by `o' or `O' command.
  301.  
  302. `vip-case-fold-search nil'
  303. `:se ic (:se ignorecase)'
  304.      If `t' search ignores cases.
  305.  
  306. `vip-re-search nil'
  307. `:se magic'
  308.      If `t' then search is reg-exp search, if `nil' then vanilla search.
  309.  
  310. `buffer-read-only'
  311. `:se ro (:se readonly)'
  312.      Set current buffer to read only. To change globally put
  313.      `(setq-default buffer-read-only t)' in your `.emacs' file.
  314.  
  315. `blink-matching-paren t'
  316. `:se sm (:se showmatch)'
  317.      Show matching parens by blinking cursor.
  318.  
  319. `tab-width t (default setting, via `setq-default')'
  320. `:se ts=value (:se tabstop=value)'
  321.      Set tab width to value for all buffers where the tab is not yet
  322.      set locally (see next), including the new buffers. Note that
  323.      typing `TAB' normally doesn't insert the tab, since this key is
  324.      usually bound to text-formatting function,
  325.      `indent-for-tab-command' (which facilitates programming and
  326.      document writing). Instead, the tab is inserted via the command
  327.      `vip-insert-tab', which is bound to `S-tab' (shift + tab).
  328.  
  329.      On some non-windowing terminals, Shift doesn't modify the `TAB'
  330.      key, so `S-tab' behaves as if it were `TAB'. In such a case, you
  331.      will have to bind `vip-insert-tab' to some other convenient key.
  332.  
  333. `tab-width t (local setting via `setq')'
  334. `:se tab-stop-local=value'
  335.      Like `:se ts', except that `tab-width' is set only for the current
  336.      buffer; it will have no effect on other buffers.
  337.  
  338. `vip-shift-width 8'
  339. `:se sw=value  (:se shiftwidth=value)'
  340.      The number of columns shifted by `>' and `<' commands.
  341.  
  342. `vip-search-wrap-around t'
  343. `:se ws (:se wrapscan)'
  344.      If `t', search wraps around the end/beginning of buffer.
  345.  
  346. `vip-tags-file-name "TAGS"'
  347.      The name of the file used as the tag table.
  348.  
  349. `vip-re-query-replace nil'
  350.      If `t', use reg-exp replace in query replace.
  351.  
  352. `vip-want-ctl-h-help nil'
  353.      If `t', `C-h' is bound to `help-command'; if `nil', it is bound to
  354.      `delete-backward-char'.
  355.  
  356. `vip-vi-style-in-minibuffer t'
  357.      If `t', Viper provides a high degree of compatibility with Vi
  358.      insert mode when you type text in the Minibuffer; if `nil', typing
  359.      in the Minibuffer feels like plain Emacs.
  360.  
  361. `vip-no-multiple-ESC t'
  362.      If you set this to `nil', you can use `ESC' as Meta in Vi state.
  363.      Normally, this is not necessary, since graphical displays have
  364.      separate Meta keys (usually on each side of the space bar). On a
  365.      dumb terminal, Viper sets this variable to `twice', which is
  366.      almost like `nil', except that double `ESC' beeps. This, too, lets
  367.      ESC to be used as a Meta.
  368.  
  369. `vip-keysequence-delay 140'
  370.      Escape sequences separated by this much delay are interpreted as
  371.      command, ignoring the special meaning of ESC in VI. The default is
  372.      suitable for most terminals. However, if your terminal is
  373.      extremely slow, you might want to increase this slightly. You will
  374.      know if your terminal is slow if the ESC key sequences emitted by
  375.      the arrow keys are interpreted as separately typed characters (and
  376.      thus the arrow keys won't work).  Making this value too large will
  377.      slow you down, so exercise restraint.
  378.  
  379. `vip-ex-style-motion t'
  380.      Set this to `nil', if you want `l,h' to cross lines, etc. *Note
  381.      Movement and Markers::, for more info.
  382.  
  383. `vip-ex-style-editing-in-insert t'
  384.      Set this to to `nil', if you want `ESC' to not move back and `C-h'
  385.      to not stop at the beginning of a line in Insert state.
  386.  
  387. `vip-always t'
  388.      Leave it to Viper to decide when a buffer must be brought up in Vi
  389.      state, Insert state, or Emacs state. This heuristics works well in
  390.      virtually all cases.  This option must be set before Viper is
  391.      loaded or in the `.vip' file.
  392.  
  393. `vip-custom-file-name "~/.vip"'
  394.      Change this if you want. Must be set in `.emacs' (not `.vip'!)
  395.      before Viper is loaded. Note that you have to set it as a string
  396.      inside double quotes.
  397.  
  398. `vip-info-file-name "viper"'
  399.      The name prefix for Viper Info files. By default, the info files
  400.      are `viper', `viper-1', etc.
  401.  
  402. `vip-spell-function 'ispell-region'
  403.      Function used by the command `#c<move>' to spell.
  404.  
  405. `ex-find-file-shell "csh"'
  406.      Shell used to interpret filenames. If you have problems with Csh,
  407.      change to something else. Note that you have to set it as a string
  408.      inside double quotes.
  409.  
  410. `ex-cycle-other-window t'
  411.      If `t', `:n' and `:b' will cycle through files in another window,
  412.      if one exists.
  413.  
  414. `ex-cycle-through-non-files nil'
  415.      `:n' does not normally cycle through buffers. Set this to get
  416.      buffers also.
  417.  
  418. `vip-automatic-iso-accents nil'
  419.      If `t', ISO accents will be turned on in insert/replace Viper
  420.      states and turned off in Vi state. This is useful for editing text
  421.      in European languages.
  422.  
  423. `vip-want-emacs-keys-in-insert'
  424.      This is set to `nil' for user levels 1 and 2 and to `t' for user
  425.      levels 3 and 4. Users who specify level 5 are allowed to set this
  426.      variable as they please (the default for this level is `t'). If
  427.      set to `nil', complete Vi compatibility is provided in Insert
  428.      state. This is really not recommended, as this precludes you from
  429.      using language-specific features provided by the major modes.
  430.  
  431. `vip-want-emacs-keys-in-vi'
  432.      This is set to `nil' for user level 1 and to `t' for user levels
  433.      2-4.  At level 5, users are allowed to set this variable as they
  434.      please (the default for this level is `t').  If set to `nil',
  435.      complete Vi compatibility is provided in Vi command state. Setting
  436.      this to `nil' is really a bad idea, unless you are a novice, as
  437.      this precludes the use of language-specific features provided by
  438.      the major modes.
  439.  
  440. `vip-keep-point-on-repeat t'
  441.      If `t', point is not moved when the user repeats the previous
  442.      command by typing `.'  This is very useful for doing repeated
  443.      changes with the `.' key.
  444.  
  445. `vip-repeat-from-history-key 'f1'
  446.      Prefix key used to invoke the macros `f1 1' and `f1 2' that repeat
  447.      the second-last and the third-last destructive command.  Both
  448.      these macros are bound (as Viper macros) to
  449.      `vip-repeat-from-history', which checks the second key by which it
  450.      is invoked to see which of the previous commands to invoke. Viper
  451.      binds `f1 1' and `f1 2' only, but the user can bind more in
  452.      `~/.vip'. *Note Vi Macros::, for how to do this.
  453.  
  454. `vip-keep-point-on-undo nil'
  455.      If `t', Viper tries to not move point when undoing commands.
  456.      Instead, it will briefly move the cursor to the place where change
  457.      has taken place. However, if the undone piece of text is not seen
  458.      in window, then point will be moved to the place where the change
  459.      took place.  Set it to `t' and see if you like it better.
  460.  
  461. `vip-delete-backwards-in-replace nil'
  462.      If `t', DEL key will delete characters while moving the cursor
  463.      backwards.  If `nil', the cursor will move backwards without
  464.      deleting anything.
  465.  
  466. `vip-replace-overlay-face 'vip-replace-overlay-face'
  467.      On a graphical display, Viper highlights replacement regions
  468.      instead of putting a `$' at the end. This variable controls the so
  469.      called "face" used to highlight the region.
  470.  
  471.      By default, `vip-replace-overlay-face' underlines the replacement
  472.      on monochrome displays and highlights it with color on  color
  473.      displays.  If you know something about Emacs faces and don't like
  474.      how Viper highlights replacement regions, you can change this
  475.      variable to specify a new face name. (Emacs faces are described in
  476.      the Emacs Lisp reference.) On a color display, the following
  477.      customization method is usually most effective:
  478.           (set-face-foreground vip-replace-overlay-face "DarkSlateBlue")
  479.           (set-face-background vip-replace-overlay-face "yellow")
  480.      For a complete list of colors available to you, evaluate the
  481.      expression `(x-defined-colors)'. (Type it in the buffer `*scratch*'
  482.      and then hit the `C-j' key.
  483.  
  484. `vip-replace-overlay-cursor-color  "Red"'
  485.      Cursor color when it is inside the replacement region.  This has
  486.      effect only on color displays and only when Emacs runs as an X
  487.      application.
  488.  
  489. `vip-replace-region-end-delimiter "$"'
  490.      A string used to mark the end of replacement regions.  It is used
  491.      only with TTYs or if `vip-use-replace-region-delimiters' is
  492.      non-nil.
  493.  
  494. `vip-replace-region-start-delimiter  ""'
  495.      A string used to mark the beginning of replacement regions.  It is
  496.      used only with TTYs or if `vip-use-replace-region-delimiters' is
  497.      non-nil.
  498.  
  499. `vip-use-replace-region-delimiters'
  500.      If non-nil, Viper will always use
  501.      `vip-replace-region-end-delimiter' and
  502.      `vip-replace-region-start-delimiter' to delimit replacement
  503.      regions, even on color displays (where this is unnecessary). By
  504.      default, this variable is non-nil only on TTYs or monochrome
  505.      displays.
  506.  
  507. `vip-toggle-key "\C-z"'
  508.      Specifies the key used to switch from Emacs to Vi and back.  Must
  509.      be set in `.vip' or prior to loading Viper. This variable can't be
  510.      changed interactively after Viper is loaded.
  511.  
  512. `vip-ESC-key "\e"'
  513.      Specifies the key used to escape from Insert/Replace states to Vi.
  514.      Must be set in `.vip' or prior to loading Viper. This variable
  515.      cannot be changed interactively after Viper is loaded.
  516.  
  517. `vip-buffer-search-char ?g'
  518.      Key used for buffer search. *Note Viper Specials::, for details.
  519.  
  520. `vip-surrounding-word-function 'vip-surrounding-word'
  521.      The value of this variable is a function name that is used to
  522.      determine what constitutes a word clicked upon by the mouse. This
  523.      is used by mouse search and insert.
  524.  
  525. `vip-search-face 'vip-search-face'
  526.      Variable that controls how search patterns are highlighted when
  527.      they are found.
  528.  
  529. `vip-vi-state-hooks nil'
  530.      List of parameterless functions to be run just after entering the
  531.      Vi command state.
  532.  
  533. `vip-insert-state-hooks nil'
  534.      Same for Insert state. This hook is also run after entering
  535.      Replace state.
  536.  
  537. `vip-replace-state-hooks  nil'
  538.      List of (parameterless) functions called just after entering
  539.      Replace state (and after all `vip-insert-state-hooks').
  540.  
  541. `vip-emacs-state-hooks nil'
  542.      List of (parameterless) functions called just after switching from
  543.      Vi state to Emacs state.
  544.  
  545. `vip-load-hooks nil'
  546.      List of (parameterless) functions called just after loading Viper.
  547.      This is the last chance to do customization before Viper is up and
  548.      running.
  549.  
  550. You can reset some of these constants in Viper with the Ex command
  551. `:set' (when so indicated in the table).  Or you can include a line
  552. like this in your `.vip' file:
  553.      (setq vip-case-fold-search t)
  554.  
  555. 
  556. File: viper,  Node: Keybindings,  Next: Packages that Change Keymaps,  Prev: Rudimentary Changes,  Up: Customization
  557.  
  558. Keybindings
  559. ===========
  560.  
  561.    Viper lets you define hot keys, i.e., you can associate keyboard keys
  562. such as F1, Help, PgDn, etc., with Emacs Lisp functions (that may
  563. already exist or that you will write). Each key has a "preferred form"
  564. in Emacs. For instance, the Up key's preferred form is [up], the Help
  565. key's preferred form is [help], and the Undo key has the preferred form
  566. [f14].  You can find out the preferred form of a key by typing `M-x
  567. describe-key-briefly' and then typing the key you want to know about.
  568.  
  569.    Under X Windows, every keyboard key emits its preferred form, so you
  570. can just type
  571.  
  572.      (global-set-key [f11] 'calendar)            ; L1, Stop
  573.      (global-set-key [f14] 'undo)                ; L4, Undo
  574.  
  575. to bind L1 so it will invoke the Emacs Calendar and to bind L4 so it
  576. will undo changes.  However, on a dumb terminal or in an Xterm window,
  577. even the standard arrow keys may not emit the right signals for Emacs
  578. to understand. To let Emacs know about those keys, you will have to
  579. find out which key sequences they emit by typing `C-q' and then the key
  580. (you should switch to Emacs state first). Then you can bind those
  581. sequences to their preferred forms using `function-key-map' as follows:
  582.  
  583.      (cond ((string= (getenv "TERM") "xterm")
  584.             (define-key function-key-map "\e[192z" [f11])    ; L1
  585.             (define-key function-key-map "\e[195z" [f14])    ; L4, Undo
  586.  
  587.    The above illustrates how to do this for Xterm. On VT100, you would
  588. have to replace "xterm" with "vt100" and also change the key sequences
  589. (the same key may emit different sequences on different types of
  590. terminals).
  591.  
  592.    The above keys are global, so they are overwritten by the local maps
  593. defined by the major modes and by Viper itself. Therefore, if you wish
  594. to change a binding set by a major mode or by Viper, read this.
  595.  
  596.    Viper users who wish to specify their own key bindings should be
  597. concerned only with the following three keymaps:
  598. `vip-vi-global-user-map' for Vi state commands,
  599. `vip-insert-global-user-map' for Insert state commands, and
  600. `vip-emacs-global-user-map' for Emacs state commands (note: customized
  601. bindings for Emacs state made to `vip-emacs-global-user-map' are *not*
  602. inherited by Insert state).
  603.  
  604.    For more information on Viper keymaps, see the header of the file
  605. `viper.el'.  If you wish to change a Viper binding, you can use the
  606. `define-key' command, to modify `vip-vi-global-user-map',
  607. `vip-insert-global-user-map', and `vip-emacs-global-user-map', as
  608. explained below. Each of these key maps affects the corresponding Viper
  609. state.  The keymap `vip-vi-global-user-map' also affects Viper's
  610. Replace state.
  611.  
  612. If you want to bind a key, say `C-v', to the function that scrolls page
  613. down and to make `0' display information on the current buffer, putting
  614. this in `.vip' will do the trick in Vi state:
  615.      (define-key vip-vi-global-user-map "\C-v" 'scroll-down)
  616.  
  617. To set a key globally,
  618.      (define-key vip-emacs-global-user-map "\C-c m" 'smail)
  619.      (define-key vip-vi-global-user-map "0" 'vip-info-on-file)
  620.  
  621. Note, however, that this binding may be overwritten by other keymaps,
  622. since the global keymap has the lowest priority.  To make sure that
  623. nothing will override a binding in Emacs state, you can write this:
  624.      (define-key vip-emacs-global-user-map "\C-c m" 'smail)
  625.  
  626. To customize the binding for `C-h' in Insert state:
  627.      (define-key vip-insert-global-user-map "\C-h" 'my-del-backwards-function)
  628.  
  629. Each Emacs command key calls some lisp function. If you have enabled the
  630. Help, (*Note Rudimentary Changes::) `C-h k' will show you the function
  631. for each specific key; `C-h b' will show all bindings, and `C-h m' will
  632. provide information on the major mode in effect. If Help is not
  633. enabled, you can still get help in Vi state by prefixing the above
  634. commands with `\', e.g., `\ C-h k' (or you can use the Help menu in the
  635. menu bar, if Emacs runs under X Windows).
  636.  
  637.    Viper users can also change bindings on a per major mode basis.  As
  638. with global bindings, this can be done separately for each of the three
  639. main Viper states.  To this end, Viper provides the function
  640. `vip-modify-major-mode'.
  641.  
  642.    To modify keys in Emacs state for `my-favorite-major-mode', the user
  643. needs to create a sparse keymap, say, `my-fancy-map', bind whatever
  644. keys necessary in that keymap, and put
  645.  
  646.      (vip-modify-major-mode 'dired-mode 'emacs-state my-fancy-map)
  647.  
  648. in `~/.vip'. To do the same in Vi and Insert states, one should use
  649. `vi-state' and `insert-state'. Changes in Insert state are also in
  650. effect in Replace state.  For instance, suppose that the user wants to
  651. use `dd' in Vi state under Dired mode to delete files, `u' to unmark
  652. files, etc. The following code in `~/.vip' will then do the job:
  653.  
  654.      (setq my-dired-modifier-map (make-sparse-keymap))
  655.      (define-key my-dired-modifier-map "dd" 'dired-flag-file-deletion)
  656.      (define-key my-dired-modifier-map "u" 'dired-unmark)
  657.      (vip-modify-major-mode 'dired-mode 'vi-state my-dired-modifier-map)
  658.  
  659.    A Vi purist may want to modify Emacs state under Dired mode so that
  660. `k', `l', etc., will move around in directory buffers, as in Vi.
  661. Although this is not recommended, as these keys are bound to useful
  662. Dired functions, the trick can be accomplished via the following code:
  663.  
  664.      (setq my-dired-vi-purist-map (make-sparse-keymap))
  665.      (define-key my-dired-vi-purist-map "k" 'vip-previous-line)
  666.      (define-key my-dired-vi-purist-map "l" 'vip-forward-char)
  667.      (vip-modify-major-mode 'dired-mode 'emacs-state my-dired-vi-purist-map)
  668.  
  669.    Similar effect can be achieved by defining Vi keyboard macros using
  670. the Ex commands `:map' and `:map!'. The difference is that multi-key Vi
  671. macros do not override the keys they are bound to, unless these keys are
  672. typed in quick succession. So, with macros, one can use the normal keys
  673. alongside with the macros. If per-mode modifications are needed, the
  674. user can try both ways and see which one is more convenient.  *Note Vi
  675. Macros::, for details.
  676.  
  677.    Note: in major modes that come up in *Emacs state* by default, the
  678. aforesaid modifications may not take place immediately (but only after
  679. the buffer switches to some other Viper state and then back to Emacs
  680. state).  To avoid this, one should add `vip-change-state-to-emacs' to an
  681. appropriate hook of that major mode. (Check the function
  682. `vip-set-hooks' in `viper.el' for examples.)  However, if you have set
  683. `vip-always' to `t', chances are that you won't need to perform the
  684. above procedure, because Viper will take care of most useful defaults.
  685.  
  686.    Finally, Viper has a facility that lets the user define per-buffer
  687. bindings, i.e., bindings that are in effect in some specific buffers
  688. only. Unlike per-mode bindings described above, per-buffer bindings can
  689. be defined based on considerations other than the major mode.  This is
  690. done via the function `vip-add-local-keys', which lets one specify
  691. bindings that should be in effect in the current buffer only and for a
  692. specific Viper state. For instance,
  693.      (vip-add-local-keys 'vi-state '(("ZZ" . TeX-command-master)
  694.                                      ("ZQ" . vip-save-kill-buffer)))
  695.  
  696. redefines `ZZ' to invoke `TeX-command-master' in `vi-state' and `ZQ' to
  697. save-then-kill the current buffer. These bindings take effect only in
  698. the buffer where this command is executed. The typical use of this
  699. function is to execute the above expression from within a function that
  700. is included in a hook to some major mode. For instance, the above
  701. expression could be called from a function, `my-tex-init', which may be
  702. added to `tex-mode-hook' as follows:
  703.      (add-hook 'tex-mode-hook 'my-tex-init)
  704.  
  705. When TeX mode starts, the hook is executed and the above Lisp
  706. expression is evaluated. Then, the bindings for `ZZ' and `ZQ' are
  707. changed in Vi command mode for all buffers in TeX mode.
  708.  
  709.    Another useful application is to bind `ZZ' to `send-mail' in the
  710. Mail mode buffers (the specifics of this depend on which mail package
  711. you are using, `rmail', `mh-e', `vm', etc.  For instance, here is how
  712. to do this for `mh-e', the Emacs interface to MH:
  713.      (defun mh-add-vi-keys ()
  714.        "Set up ZZ for MH-e and XMH."
  715.        (vip-add-local-keys 'vi-state '(("ZZ" . mh-send-letter))))
  716.      (add-hook 'mh-letter-mode-hook 'mh-add-vi-keys)
  717.  
  718.    You can also use `vip-add-local-keys' to set per buffer bindings in
  719. Insert state and Emacs state by passing as a parameter the symbols
  720. `'insert-state' and `'emacs-state', respectively.  As with global
  721. bindings, customized local bindings done to Emacs state are not
  722. inherited by Insert state.
  723.  
  724.    So much about Viper-specific bindings.  *Note Customization:
  725. (emacs)Customization, and the Emacs quick reference card for the
  726. general info on key bindings in Emacs.
  727.  
  728. 
  729. File: viper,  Node: Packages that Change Keymaps,  Next: Viper Specials,  Prev: Keybindings,  Up: Customization
  730.  
  731. Packages that Change Keymaps
  732. ----------------------------
  733.  
  734.    Viper is designed to coexist with all major and minor modes of
  735. Emacs. This means that bindings set by those modes are generally
  736. available with Viper (unless you explicitly prohibit them by setting
  737. `vip-want-emacs-keys-in-vi' and `vip-want-emacs-keys-in-insert' to
  738. `nil').  If `vip-always' is set to `t', Viper will try to bring each
  739. buffer in the a Viper state that is most appropriate for that buffer.
  740. Usually, this would be the Vi state, but sometimes it could be the
  741. Insert state or the Emacs state.
  742.  
  743.    Some major mode bindings will necessarily be overwritten by Viper.
  744. Indeed, in Vi state, most of the 1-character keys are used for Vi-style
  745. editing.  This usually causes no problems because most packages
  746. designed for editing files typically do not bind such keys. Instead,
  747. they use key sequences that start with `C-x' and `C-c'. This is why it
  748. was so important for us to free up `C-x' and `C-c'.  It is common for
  749. language-specific major modes to bind `TAB' and `LFD' (the line feed)
  750. keys to various formatting functions. This is extremely useful, but may
  751. require some getting used to for a Vi user. If you decide that this
  752. feature is not for you, you can re-bind these keys as explained earlier
  753. (*Note Customization::).
  754.  
  755.    Binding for `TAB' is one of the most unusual aspects of Viper for
  756. many novice users.  In Emacs, `TAB' is used to format text and
  757. programs, and is extremely useful. For instance, hitting `TAB' causes
  758. the current line to be re-indented in accordance with the context.  In
  759. programming, this is very important, since improper automatic
  760. indentation would immediately alert the programmer to a possible error.
  761. For instance, if a `)' or a `"' is missing somewhere above the current
  762. line, `TAB' is likely to mis-indent the line.
  763.  
  764.    For this reason, Viper doesn't change the standard Emacs binding of
  765. `TAB', thereby sacrificing Vi compatibility (except for users at level
  766. 1). Instead, in Viper, the key `S-tab' (shift+ tab) is chosen to
  767. emulate Vi's `TAB'.
  768.  
  769.    We should note that on some non-windowing terminals, Shift doesn't
  770. modify the `TAB' key, so `S-tab' behaves as if it were `TAB'. In such a
  771. case, you will have to bind `vip-insert-tab' to some other convenient
  772. key.
  773.  
  774.    Some packages, notably Dired, Gnus, Info, etc., attach special
  775. meaning to common keys like `SPC', `x', `d', `v', and others. This
  776. means that Vi command state is inappropriate for working with these
  777. packages. Fortunately, these modes operate on read-only buffers and are
  778. designed not for editing files, but for special-purpose browsing,
  779. reading news, mail, etc., and Vi commands are meaningless in these
  780. situations. For this reason, Viper doesn't force Vi state on such major
  781. modes.  Rather, it brings them in Emacs state. You can switch to Vi
  782. state by typing `C-z' if, for instance, you want to do Vi-style search
  783. in a buffer (although, usually, incremental search, which is bound to
  784. `C-s', is sufficient in these situations). But you should then switch
  785. back to Emacs state if you plan to continue using these major modes
  786. productively. You can also switch to Vi temporarily, to execute one
  787. 1-character command. This is done by typing `M-C-z' (or `ESC C-z').
  788. This facility cannot execute several complex Vi commands, such as `dw',
  789. `de', etc.
  790.  
  791.    It is also possible to harness some major modes, even though they
  792. may bind common keys to specialized commands. Harnessing can make sense
  793. for modes that bind only a small number of common keys.  For instance,
  794. if `vip-always' is set to `t' in your `~/.vip' file, Viper will harness
  795. the Shell mode by changing the bindings for `C-m' and `C-d' using
  796. `vip-add-local-keys' described in section on customization (*Note
  797. Customization::). In general, there is no single recipe for harnessing
  798. modes. It can be as simple as adding the function `viper-mode' to a
  799. hook associated with the mode, or it can be more complex, as in the
  800. case of Shell mode and Emerge. Take a look at `vip-set-hooks' function
  801. for some examples.
  802.  
  803.    Conversely, it may be the case that most of the major modes harnessed
  804. by `vip-set-hooks' function fit your working style, except one or two
  805. cases. In this case, you may still be able to set `vip-always' to `t'
  806. and then remove a hook that forces Vi command state. For instance, to
  807. unharness `lisp-interaction-mode', you can put the following line in
  808. your `.emacs' (not `.vip'!) file after `(require 'viper)':
  809.      (remove-hook 'lisp-interaction-mode-hook 'viper-mode)
  810.  
  811.    In some rare cases, some minor modes may override certain essential
  812. bindings in Vi command state.  This is not really catastrophic because
  813. this may happen only in the beginning, when the minor mode kicks in.
  814. Switching to Insert state and then back to Vi state will correct the
  815. situation.  Viper knows about several such minor modes and takes care
  816. of them, so that the above trick won't be necessary.  If you find that
  817. some minor mode, e.g., `nasty-mode.el' interferes with Viper, putting
  818. the following in `.vip' should fix the problem:
  819.      (vip-harness-minor-mode "nasty-mode")
  820.  
  821. The argument to `vip-harness-minor-mode' is the name of the file for the
  822. offending minor mode with the suffixes `.el' and `.elc' removed.
  823.  
  824.    It may be tricky, however, to find out which minor mode is at fault.
  825. The only guidance here is to look into the file that defines the minor
  826. mode you are suspecting, say `nasty-mode.el', and see if it has a
  827. variable called `nasty-mode-map'. Then check if there is a statement of
  828. the form
  829.      (define-key nasty-mode-map key function)
  830.  
  831. that binds the misbehaving keys. If so, use the above line to harness
  832. `nasty-mode'. If your suspicion is wrong, no harm is done if you
  833. harness a minor mode that doesn't need to be harnessed.
  834.  
  835.